package com.my.cd.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 植物简单工厂类
 */
public class PlantFactory {

    private Map<Integer, Plant> plantMap = new HashMap<>();

    public PlantFactory() {

    }

    public Plant getPlant(int type) {
        if (!plantMap.containsKey(type)) {
            switch (type) {
                case 0:
                    plantMap.put(0, new Tree());
                    break;
                case 1:
                    plantMap.put(1, new Grass());
                    break;
            }
        }
        return plantMap.get(type);
    }
}
